﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Exceptionless;
using Microsoft.AspNetCore.Mvc;
using LogDemo.Models;

namespace LogDemo.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {

            try
            {
                throw new Exception("相互引用!增强版本");
            }
            catch (Exception e)
            {
                var guid = Guid.NewGuid().ToString();
                e.ToExceptionless()
                 .SetHttpContext(this.HttpContext)  //指定Request Tab页面
                 .AddTags("DemoTags")                //制定Tag页面
                                                     //.SetProperty("setProperty",new{setProperty=new
                                                     //   {
                                                     //       username="kangze",
                                                     //       age=20,
                                                     //   }},2,new List<string>(){"username"}) 
                    .SetProperty("ExtendData", new { username = "kangze", age = 20 })
                    
                 .SetReferenceId(guid)
                 .SetEventReference("父级日志", guid)
                 .SetType("ERP系统错误")             //制定错误的类型
                 .SetUserDescription("kangze25@126.com", "康泽的描述")  //用户描述
                 .SetUserIdentity("ID:9547", "kangze")  //用户信息
                 .SetMessage("重写消息")                //重写消息
                 .SetSource("ERP接口报错")               //错误来源
                 .Submit();

            }
            return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";
            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
